package com.lp.aop.jdk;

import com.lp.aop.Animal;
import com.lp.aop.Cat;
import org.springframework.aop.framework.ProxyCreatorSupport;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;

/**
 * @author: lp
 * @create: 2024-04-10 7:34
 * @description: TODO
 */
public class SpringTest {
	public static void main(String[] args) {
		//1.创建被代理对象
		Cat cat = new Cat();
		//2.创建spring代理工厂对象(config+Factory，有aop所有资料)

		//ProxyFactory extends ProxyCreatorSupport extends AdvisedSupport extends ProxyConfig implements Advised
		//ProxyFactory创建
		ProxyFactory proxyFactory = new ProxyFactory(cat);

		//3.添加拦截

		//自定义PointCut和拦截器
		proxyFactory.addAdvisor(new DefaultPointcutAdvisor(new MyPointCut(),new MethodInterceptor1()));
		proxyFactory.addAdvisor(new DefaultPointcutAdvisor(new MyPointCut(),new MethodInterceptor2()));


		//用默认PointCut，拦截所有类和方法
		//MethodInterceptor extends Interceptor extends Advice
		//proxyFactory.addAdvice(new MethodInterceptor1());

		//proxyFactory.addAdvice(new MethodInterceptor2());

		//4.获取代理对象
		//aop源码入口
		Animal animal= (Animal)proxyFactory.getProxy();

		animal.eat();

		animal.go();

	}
}
